package com.yitao.cms.controller.product;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedInput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.constant.ProductConstant;
import com.yitao.client.dto.enums.EnumDto;
import com.yitao.client.dto.product.OperationProductCategoryDto;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.dto.productCategory.ProductCategoryDetailDto;
import com.yitao.cms.dto.productCategory.ProductCategoryGroupDto;
import com.yitao.cms.service.product.OperationProductCategoryService;
import com.yitao.cms.service.product.ProductCategoryRelationService;
import com.yitao.cms.vo.product.ProductInfoByCategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
/**
  * @Author:Wwl
  * @Description:
  * @Date:14:46 2019/3/9
  */
@Api(value = "/cms/productCategory", description = "商品运营分类运营后台相关接口", tags = {"cms-product-category"})
@RestController
@RequestMapping(value = "/productCategory", produces = {"application/json"})
public class ProductCmsCategoryController {
    @Autowired
    private OperationProductCategoryService operationProductCategoryService;
    @Autowired
    private ProductCategoryRelationService productCategoryRelationService;
    @ApiOperation("新增/编辑运营分类(编辑时需传递id及原有数据)")
    @LogAnnotation(targetType = "productCategory-save", remark = "新增/编辑运营分类")
    @RequestMapping(value = "/save/operationProductCategory", method = RequestMethod.POST)
    public DataOutput<OperationProductCategoryDto> save(@RequestBody OperationProductCategoryDto operationProductCategoryDto, HttpServletRequest request) {
        return operationProductCategoryService.updateProductCategory(operationProductCategoryDto,request);
    }

    @ApiOperation("运营分类类型枚举")
    @RequestMapping(value = "/get/productCategoryRecommendType",method = RequestMethod.POST)
    public DataOutput<EnumDto> getProductCategoryRecommendTypeEnum(){
        return new DataOutput(ProductConstant.ProductCategoryRecommendType.getProductCategoryRecommendTypeEnum());
    }
    @ApiOperation("运营分类数据删除")
    @LogAnnotation(targetType = "productCategory-delete", remark = "运营分类数据删除")
    @RequestMapping(value = "/delete/productCategoryById",method = RequestMethod.POST)
    public DataOutput deleteProductCategoryById(
            @ApiParam(value = "运营分类数据Id") @RequestParam(value = "categoryId") Long categoryId){
        return operationProductCategoryService.deleteProductCategoryById(categoryId);
    }
    @ApiOperation("运营分类数据详情")
    @RequestMapping(value = "/findProductCategoryById",method = RequestMethod.POST)
    public DataOutput<ProductCategoryDetailDto> findProductCategoryById(
            @ApiParam(value = "运营分类数据Id") @RequestParam(value = "categoryId") Long categoryId){
        return operationProductCategoryService.findProductCategoryById(categoryId);
    }
    @ApiOperation("运营分类树形列表数据")
    @RequestMapping(value = "/findProductCategoryTreeList",method = RequestMethod.POST)
    public DataOutput<OperationProductCategoryDto> findProductCategoryTreeList(HttpServletRequest request){
        return operationProductCategoryService.findProductCategoryList(request);
    }
    @ApiOperation("运营分类列表数据查询")
    @RequestMapping(value = "/findProductCategoryList",method = RequestMethod.POST)
    public PagedOutput<OperationProductCategoryDto> findProductCategoryList(
            HttpServletRequest request,
            @ApiParam(value = "分类类型") @RequestParam(value = "categoryType", required = false) Integer categoryType,
            @ApiParam(value = "分类级别")@RequestParam(value = "categoryLevel", required = false) Integer categoryLevel,
            @ApiParam(value = "商品分类名") @RequestParam(value = "categoryName",required = false) String categoryName,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo", required = true) Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize", required = true) Integer pageSize
    ){
        PagedInput pagedInput = new PagedInput(pageSize, pageNo);
        return operationProductCategoryService.findProductCategoryList(request,categoryType,categoryLevel,categoryName,pagedInput);
    }
    @ApiOperation("运营分类-管理商品")
    @RequestMapping(value = "/findProductInfoByCategoryId",method = RequestMethod.POST)
    public PagedOutput<ProductInfoByCategoryVo> findProductInfoByCategoryId(
            @ApiParam(value = "运营分类Id")@RequestParam(value = "categoryId") Long categoryId,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo", required = true) Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize", required = true) Integer pageSize){
        return productCategoryRelationService.findProductInfoByCategoryId(categoryId,pageNo,pageSize);
    }

    @ApiOperation("运营分类-分组至")
    @RequestMapping(value = "/updateCategoryAndProductId",method = RequestMethod.POST)
    public DataOutput updateCategoryAndProductId(
            @RequestBody ProductCategoryGroupDto productCategoryGroupDto){
        return productCategoryRelationService.updateCategoryAndProductId(productCategoryGroupDto);
    }
    @ApiOperation("运营分类-关联数据删除")
    @RequestMapping(value = "/deleteCategoryAndProductId",method = RequestMethod.POST)
    public DataOutput deleteCategoryAndProductId(
            @ApiParam(value = "产品Id")@RequestParam(value = "productId") Long productId,
            @ApiParam(value = "运营分类Id")@RequestParam(value = "categoryId") Long categoryId){
        return productCategoryRelationService.deleteCategoryAndProductId(productId,categoryId);
    }
}
